package com.paomi.client.activity.classify.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.paomi.client.GlideApp;
import com.paomi.client.R;
import com.paomi.client.activity.detail.DetailTicketActivity;
import com.paomi.client.activity.newsDetail.NewsDetailActivity;
import com.paomi.client.activity.newsDetail.model.NewsListJson;
import com.paomi.client.fragment.first.model.TicketJson;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 演出详情
 */
public class ShopListAdapter extends RecyclerView.Adapter<ShopListAdapter.ViewHolder> {
    Context context;
    List<TicketJson> list = new ArrayList<>();

    public ShopListAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<TicketJson> data) {
        this.list = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_search_classify, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TicketJson newsListJson = list.get(position);
        GlideApp.with(context).load(newsListJson.getThumb()).placeholder(R.mipmap.img_default_msg).into(holder.performIv);
        holder.shopName.setText(newsListJson.getName());
        holder.shopDate.setText(newsListJson.getDate());
        holder.shopMoney.setText("¥" + newsListJson.getPrice());
        holder.numPays.setText(newsListJson.getPay_number() + "人付款");
        switch (newsListJson.getTicket_state()){//0是演出结束，1是预售中，2售票中，3扫尾票，4已售罄，5即将开票
            case 0:
                holder.shopBtn.setText(context.getResources().getString(R.string.ticket_un));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_cbcbcb));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_gray);
                break;
            case 1:
                holder.shopBtn.setText(context.getResources().getString(R.string.ticketing_begin));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_F01F07));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_f01f07);
                break;
            case 2:
                holder.shopBtn.setText( context.getResources().getString(R.string.ticketing));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_F01F07));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_f01f07);
                break;
            case 3:
                holder.shopBtn.setText( context.getResources().getString(R.string.ticket_none));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_F01F07));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_f01f07);
                break;
            case 4:
                holder.shopBtn.setText(context.getResources().getString(R.string.ticket_finish));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_cbcbcb));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_gray);
                break;
            case 5:
                holder.shopBtn.setText(context.getResources().getString(R.string.ticket_action));
                holder.shopBtn.setTextColor(context.getResources().getColor(R.color.color_F01F07));
                holder.shopBtn.setBackgroundResource(R.drawable.bg_oreder_list_btn_f01f07);
                break;
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailTicketActivity.class);
                intent.putExtra("getId", "" + newsListJson.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.perform_iv)
        RoundedImageView performIv;
        @BindView(R.id.shop_name)
        TextView shopName;
        @BindView(R.id.shop_date)
        TextView shopDate;
        @BindView(R.id.shop_money)
        TextView shopMoney;
        @BindView(R.id.num_pays)
        TextView numPays;
        @BindView(R.id.shop_btn)
        TextView shopBtn;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
